<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>基本信息</title>
<link rel="stylesheet" href="/js/layui-2.5.4/css/layui.css">
<script src="/js/layui-2.5.4/layui.js"></script>
</head>
<body>
	<blockquote class="layui-elem-quote">基本设置</blockquote>
	<form id="update-admin-form" class="layui-form layui-form-pane"
		lay-filter="update-admin-form">
		<table class="layui-table" lay-skin="row">
			<tbody>
				<tr style="display: none;">
					<td>
						<!-- <div class="layui-form-item" style="display: none;"> -->
						<div class="layui-form-item">
							<label class="layui-form-label">id</label>
							<div class="layui-input-block">
								<input id="idS" type="text" name="id" class="layui-input"
									readonly>
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="layui-form-item">
							<label class="layui-form-label">用户名</label>
							<div class="layui-input-block">
								<input type="text" lay-verify="required" name="username" class="layui-input"
									autocomplete="off" placeholder="请输入用户名" maxlength="20">
							</div>
						</div>
					</td>
					<td>
						<div class="layui-form-item">
							<label class="layui-form-label">真实姓名</label>
							<div class="layui-input-block">
								<input type="text" lay-verify="required" name="name" class="layui-input"
									autocomplete="off" placeholder="请输入姓名" maxlength="20">
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="layui-form-item">
							<label class="layui-form-label">Q&nbsp;Q</label>
							<div class="layui-input-block">
								<input type="text" lay-verify="required" name="qq" class="layui-input"
									placeholder="请输入QQ" onkeyup="value=value.replace(/[^\d]/g,'')"
									autocomplete="off" maxlength="20">
							</div>
						</div>
					</td>
					<td><div class="layui-form-item">
							<label class="layui-form-label">电话</label>
							<div class="layui-input-block">
								<input type="text" name="phone" class="layui-input"
									placeholder="请输入联系电话"
									onkeyup="value=value.replace(/[^\d]/g,'')" autocomplete="off"
									maxlength="13">
							</div>
						</div></td>
				</tr>
			</tbody>
		</table>
		<div class="layui-form-item" style="text-align: center;">
			<button class="layui-btn" lay-submit
				lay-filter="update-admin-form-submit">提交</button>
			<button class="layui-btn layui-btn-primary" type="reset">清空</button>
		</div>
	</form>

	<script>
		//JavaScript代码区域
		layui.use(
				[ 'jquery', 'layer', 'element', 'upload', 'form' ],
				function() {
					var $ = layui.$;
					var layer = layui.layer;
					var element = layui.element;
					var laydate = layui.laydate;
					var form = layui.form;
					var upload = layui.upload;
					//基本数据加载
					$.ajax({
						url : "/report/findloginA",
						type : "GET",
						contentType : 'application/json',
						dataType : 'json',
						success : function(data) {
							form.val('update-admin-form', {
								"id" : data.admin.id,
								"username" : data.admin.username,
								"name" : data.admin.name,
								"phone" : data.admin.phone,
								"qq" : data.admin.qq
							});

						},
						error : function() {
							console.log("ajax error");
						}
					});
					$('#update-admin-form')[0].reset();
					// 用户信息表单提交
					form.on('submit(update-admin-form-submit)',
							function(data) {
								// ajax方式更新用户
								$.ajax({
									url : "/admin/update",
									type : "PUT",
									//data : data,
									data : JSON.stringify(data.field),
									contentType : 'application/json',
									dataType : 'json',
									success : function(data) {
										if (data.status == 1) {
											layer.close(layer.index);
											parent.layer.msg(data.msg, {
												icon : 1,
												shade : 0.3,
												time : 2000
											})
										} else {
											parent.layer.msg(data.msg, {
												icon : 2,
												shade : 0.3,
												time : 2000
											});
										}
									},
									error : function() {
										layer.open({
											title : '系统提示',
											content : '发生未知错误，请联系管理员！'
										});
									}
								});
								// 阻止表单跳转
								return false;
							});

				});
	</script>

</body>
</html>